<template>
      <el-form :model="finacialForm" ref="finacialForm" :inline="true" label-width="72px" :label-position="'left'">
        <el-row class="search-title">条件搜索</el-row>
        <el-row>
          <el-form-item prop="record_company">
            <el-col style="width: 75px">
              <span style="font-size: 12px; font-weight: bold; color: #7A7A7A;">单位名称</span>
            </el-col>
            <el-checkbox-group v-model="finacialForm.record_company" @change="getOrgValue">
              <el-checkbox  v-for="item in company" :label="item.orgid" >{{item.orgname}}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-row>
        <el-form-item prop="sdate" label="日期范围">
          <el-date-picker v-model="sdate"
                          value-format= "yyyy-MM-dd"
                          :picker-options="pickerOptions"
                          type="daterange"
                          range-separator="-"
                          start-placeholder="开始日期"
                          end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item> <el-button class="btn-search" type="primary"  @click="submitForm(finacialForm,1)">搜索
        </el-button></el-form-item>
        <!--<el-form-item prop="record_check" label="是否分区">-->
          <!--<el-checkbox :disabled='check' v-model="finacialForm.record_check" style = "width : 150px">分区统计</el-checkbox>-->
        <!--</el-form-item>-->
        <!--<collapse-vertical>-->
          <!--<div v-show="isDisplay">-->
        <!---->
        <!--<div>-->
         <!---->
          <!--<el-form-item>-->
            <!--<el-button class="btn-mini-form"  @click="submitForm(finacialForm,1)"-->
                       <!--size="mini" >提交-->
            <!--</el-button>-->
            <!--<el-button class="btn-mini-form"  @click="resetForm('finacialForm')"-->
                       <!--size="mini" >重置-->
            <!--</el-button>-->
          <!--</el-form-item>-->
        <!--</div>-->
          <!--</div>-->
        <!--</collapse-vertical>-->
        <!--<el-row style="text-align: center"><el-button style="border: none;background-color: transparent" size="small" @click="isShow" :icon="isDisplay?'el-icon-arrow-up':'el-icon-arrow-down'">-->
        <!--</el-button></el-row>-->
          <!--<el-button type="primary" icon="el-icon-search" @click="submitForm(finacialForm,1)">查询</el-button>-->
          <!--<el-button type="danger" icon="el-icon-refresh" @click="resetForm('finacialForm')">重置</el-button>-->

      </el-form>
</template>
<script>
  /* eslint-disable */
  import { selDictonary, selDictonaryValue } from '../../../api/dictionary'
  import { searchFinancialDataStatistics, getOrgsForFinancial } from '../../../api/financialDataStatistics'
  import ElFormItem from "element-ui/packages/form/src/form-item";
  import CollapseVertical from '../../../utils/collapseVertical'

  export default {
    components: {ElFormItem,CollapseVertical},
    name: 'f-data-child-form',
    data() {
      return {
        isDisplay:false,
        finacialForm: {
         // record_start: '',     // 时间
          record_company: [],   // 单位
        },
        orglist:[],
        check : true,
        comName: '',
        company: [],
        sdate:[],        // 时间
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now() - 8.64e6
          }
        },
      }
    },
    mounted: function() {
     getOrgsForFinancial().then(res=>{
          this.company=res;
        })
    },
    props: ['pageNum', 'ranNum','pageSize'],
    watch: {
      pageNum: function(val) {
        this.submitForm()
      },
      ranNum: function(val) {
        this.submitForm()
      },
      pageSize: function(val) {
        this.submitForm()
      },
      'finacialForm.record_company': function(val) {
          if(val == "751154a1ca894c6abd5cc8f8b0d11009") {
           this.check = false
          }
      },
      sdate: function(val){
        //this.finacialForm.record_start = val;
        if (val.length == 2) {
　　　　　　　let start = new Date(Date.parse(val[0])).getMonth();
             let end =  new Date(Date.parse(val[1])).getMonth();
               if (start !== end) {
                  this.$message({
                    message :'不能跨月查询',
                    type: 'warn'
                  });
                  this.sdate = [];
               }　
        }

      }
    },
    methods: {
      submitForm: function() {

        this.$emit('tableLoad', true)
        searchFinancialDataStatistics(this.orglist,this.sdate, this.pageNum,this.pageSize).then(res => {
            this.$emit('tableData', res)
            this.$emit('tableLoad', false)
       })
      },
      getOrgValue(value) {
       this.orglist=[]
        for(var v of this.finacialForm.record_company){
          for(var item of this.company){
            if(item.orgid==v){
              this.orglist.push({orgno:item.orgid,orgname:item.orgname})
            }
          }
        }

      },
      resetForm(finacialForm) {
        this.$refs[finacialForm].resetFields();
        this.sdate = [];
      },
      isShow(){
        this.isDisplay =!this.isDisplay
      }
    }
  }
</script>

<style scoped>
</style>
